package spring.my.db.sharding.demo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import spring.my.db.sharding.demo.response.CommonResponse;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/demo")
public class HelloController {


    @ResponseBody
    @RequestMapping(value = "/hi", method = RequestMethod.GET)
    public CommonResponse<String> demo() {
        return CommonResponse.getInstance("ok" + LocalDateTime.now().toString());
    }

    @ResponseBody
    @RequestMapping(value = "/null", method = RequestMethod.GET)
    public CommonResponse<String> error() {
        List<String> list = null;
        return CommonResponse.getInstance(list.get(0));
    }

    public static final String DATE_TIME = "yyyy-MM-dd HH:mm:ss";

    public static void main(String[] args) {
        try {
            DateFormat dateFormat = new SimpleDateFormat(DATE_TIME);
            Date date = dateFormat.parse("2019-01-01 13:12:13");
            System.out.println(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        String time = "2019-01-01T12:11:20";
        LocalDateTime dateTime = LocalDateTime.parse(time);
        System.out.println(dateTime);
    }

}
